"""
添加产品页面类
"""
from selenium.common import NoSuchElementException

from framwork.pages.base_page import BasePage
from selenium.webdriver.common.by import By


class AddProductPage(BasePage):
    url = '/crm/index.php?m=product&a=add'
    product_name_locator = (By.ID, 'name')
    development_team_locator = (By.ID, 'development_team')
    btn_save_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')

    def input_product_name(self, name):
        """输入产品名称"""
        self.send_keys(self.product_name_locator, name)

    def input_development_team(self, team):
        self.find_element(self.development_team_locator).send_keys(team)

    def click_btn_save(self):
        self.find_element(self.btn_save_locator).click()

    def product_name(self):
        try:
            text = self.find_element(self.product_name_locator).text
        except NoSuchElementException:
            text = ""
        return text
